<?php

namespace App\Http\Admin\Controllers\Order;


use App\Http\Admin\Services\Order\OrderService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class OrderController extends Controller
{
    protected $service;

    public function __construct(OrderService $orderService)
    {
        $this->service = $orderService;
    }

    /*
     * 主播订单页面
     * */
    public function index()
    {
        return view('order.liver_order');
    }

    /*
     * 工厂订单页面
     * */
    public function manu()
    {
        return view('order.manu_order');
    }

    /*
     * 物流查询页面
     * */
    public function logistics()
    {
        return view('order.logistics');
    }

    /*
     * 订单修改
     * */
    public function orderEdit(Request $request)
    {
        $attributes = $request->all();

        $result = $this->service->orderEdit($attributes);

        return res('修改成功', $result);
    }

    /*
     * 订单导入
     * */
    public function orderImport()
    {
        $result = $this->service->orderImport();
        return res('ok', $result);
    }

    /*
     * 订单状态统计
     * */
    public function OrderStatusCount(Request $request)
    {
        $conditions = $request->all();

        $result = $this->service->OrderStatusCount($conditions);

        return res('订单状态统计', $result);
    }


    /*
     * 主播订单统计
     * */
    public function OrderLiverCount(Request $request)
    {
        $conditions = $request->all();

        $result = $this->service->OrderLiverCount($conditions);

        return res('主播订单统计', $result);
    }

    /*
     * 厂家订单统计
     * */
    public function OrderManuCount(Request $request)
    {
        $conditions = $request->all();

        $result = $this->service->OrderManuCount($conditions);

        return res('厂家订单统计', $result);
    }

    /*
     * 订单列表查询
     * */
    public function orderList(Request $request)
    {
        $conditions = $request->all();

        $result = $this->service->orderList($conditions);

        return res('订单列表', $result);
    }

    /*
     * 导出excel
     * */
    public function orderExp(Request $request)
    {
        $conditions = $request->all();

        //导出excel
        $this->service->orderExp($conditions);
    }

    /*
  * 导出excel(产品销量)
  * */
    public function goodsExp(Request $request)
    {
        $conditions = $request->all();

        //导出excel
        $this->service->goodsExp($conditions);
    }

    /*
     * 订单物流任务创建
     * */
    public function logisticsTask()
    {

        $result = $this->service->logisticsTask();
        return res('ok', $result);
    }

    /*
     * 临时订单任务创建
     * */
    public function logisticsTmpTask()
    {
        $result = $this->service->logisticsTmpTask();
        return res('ok', $result);
    }

    /*
     * 订单物流查询
     * */
    public function logisticsQuery(Request $request)
    {
        $taskname = $request->input('taskname', null);
        $result = $this->service->logisticsQuery($taskname);
        if ($result) {
            return res('ok', $result);
        } else {
            return err('no', $result);
        }
    }

    /*
     * 导出excel  物流
     * */
    public function logisticsExp(Request $request)
    {
        $conditions = $request->input('data');

        //导出excel
        $this->service->logisticsExp($conditions);
    }

    /*退款登记*/
    public function storeRefund(Request $request)
    {
        $conditions = $request->all();
        $this->service->storeRefund($conditions);
        return res('登记完成');
    }


}